//////////////////////////////////////////////////////////////////////////
// FileName:OLinkButton
// CreateBy:DragonXiong
// CreateDate:2009-01-08
// Description:
//		Class OLinkButton,Used to Auto Visible by User Permission 
//      
// Modify Log:
//	
// Copyright:ASL-MIS
/////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Auto.Web.Common
{
    /// <summary>
    /// Operation Button
    /// </summary>
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:OButton runat=server></{0}:OButton>")]
    public class OLinkButton : LinkButton
    {
        /// <summary>
        /// Contructed Function
        /// </summary>
        public OLinkButton()
        {
          
        }

        /// <summary>
        /// Operate Type
        /// </summary>
        [DefaultValue(OButtonType.OP_NORMAL), DisplayName("ButtonType"), Description("Operate Type"), Category("OButton")]
        public OButtonType ButtonType
        {
            get
            {
                object obj = this.ViewState["ButtonType"];
                return ((obj == null) ? OButtonType.OP_NORMAL : ((OButtonType)obj));
            }
            set
            {
                this.ViewState["ButtonType"] = value;
            }
        }

        /// <summary>
        /// Enable Operate Or Not
        /// </summary>
        [DefaultValue(true), DisplayName("EnableOperate"), Description("Enable Operate"), Category("OButton"), Browsable(false)]
        public bool EnableOperate
        {
            get
            {
                return (ViewState["EnableOperate"] == null) ? true : (Boolean)ViewState["EnableOperate"];
            }
            set
            {
                ViewState["EnableOperate"] = ConfigHelper.GetConfigBool("EnableOperate");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(true), DisplayName("Visible"), Description("Visible"), Category("OButton"), Browsable(true)]
        public override bool Visible
        {
            get
            {
                return (ViewState["Visible"] == null) ? true : (Boolean)ViewState["Visible"];
            }
            set
            {
                if (!EnableOperate)
                {
                    ViewState["Visible"] = value;
                }
                else
                {
                    ViewState["Visible"] = value;
                }
            }
        }

        /// <summary>
        /// OnInit()
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            if (EnableOperate)
            {

                this.Visible = SessionBox.User.IsAccessFuncOperates(SessionBox.CurrentSystem, PathHelper.URL, SessionBox.CultrueInfo, ButtonType.ToString());
            }

        }
    }
}
